#  Name:		netrates
#  Version:		0.1
#  Part Of:		linuxrules
#  Modified:	Sun Nov 21 2010, 23:18:19

#  See COPYING for linuxrules GPL3 licensing info.

function byterate()
{
    NR=0
	while ((getline < "/proc/net/dev") > 0) {
        NR++
        if (NR > 2)
        {
            sub(":", "", $1)
            iface = toupper($1)

            if ((iface "_RX") in _net)
                _net[iface "_RX"] = int($2  / 1024) - _net[iface "_RX"]
            else
                _net[iface "_RX"] = int($2  / 1024)

            if ((iface "_TX") in _net)
                _net[iface "_TX"] = int($10 / 1024) - _net[iface "_TX"]
            else
                _net[iface "_TX"] = int($10 / 1024)
        }
	}

	close("/proc/net/dev")
}

BEGIN {
# TODO polish this mechanism, it is too stupid to
# pretend nothing happens with it :p
# * Clean cpuload.awk
# * Clean this with the old save-to-mem mechanism

    byterate()
    system("sleep 0.1")
    byterate()
}

#  vim:ft=awk:
